package com.lh.blogConsumer.service.Impl;

import com.lh.blogCommon.util.PageUtils;
import com.lh.blogCommon.util.Query;
import com.lh.blogConsumer.entity.PersonalCenterEntity;
import com.lh.blogConsumer.feign.OssFeignService;
import com.lh.blogConsumer.mapper.PersonalCenterMapper;
import com.lh.blogConsumer.service.PersonalCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.StringUtils;


@Service("personalCenterService")
public class PersonalCenterServiceImpl extends ServiceImpl<PersonalCenterMapper, PersonalCenterEntity> implements PersonalCenterService {

    @Autowired
    OssFeignService ossFeignService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<PersonalCenterEntity> queryWrapper = new QueryWrapper<>();

        String key = (String) params.get("key");
        System.out.println(params);
        if(!StringUtils.isEmpty(key)){
            queryWrapper.eq("center_id",key).or()
                    .eq("name",key).or()
                    .eq("qq", key).or()
                    .eq("weixin",key).or()
                    .eq("phone",key).or()
                    .eq("education_background",key);

        }
        queryWrapper.orderByDesc("center_id");

        IPage<PersonalCenterEntity> page = this.page(
                new Query<PersonalCenterEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void removeAdImageByIds(String[] centerIds) {
        List<String> imgs = baseMapper.selectBatchIds(Arrays.asList(centerIds)).stream().map((item) -> {
            return item.getProfilePicture();
        }).collect(Collectors.toList());
        ossFeignService.removeList(imgs);
    }

}